function numFormat(num, cent) {
    var isThousand = 1;
    // 检查传入数值为数值类型
    if (isNaN(num) || num === undefined || num === null || num === "" || num === "null") {
        return num;
    } else {
        num = num.toString().replace(/\$|\,/g, '');
    }
    var cent_length;
    var newNum = "";
    //判断格式化类型是否包含小数点
    if (cent.indexOf(".") > 0) {
        num = num.toString();
        var after_decimal_point = '';
        var before_decimal_point = "";
        var after_decimal_point_split = num.split('.').filter(function (item) {
            return item != '';
        });
        if (after_decimal_point_split.length > 1) {
            //获取数值中小数点后的数字
            before_decimal_point = after_decimal_point_split[0].length;
            after_decimal_point = after_decimal_point_split[1].length;
        } else if (after_decimal_point.length == 1) {
            before_decimal_point = after_decimal_point_split[0].length;
            after_decimal_point = 0;
        } else {
            before_decimal_point = 0;
            after_decimal_point = 0;
        }
        var after_format = '';
        var after_format_split = cent.split('.').filter(function (item) {
            return item != '';
        });
        if (after_format_split.length > 1) {
            after_format = after_format_split[1];
        } else {
            after_format = 0;
        }
        var after_format_length = after_format.length; //获取格式化后的小数点的值的长度
        var getrequired = after_format.replace(/#/g, '').length; //获取格式化后小数点后0的位数（必填）
        newNum = new Decimals(num);
        //如果小数点后的位数小于获取格式化0后小数点后0的位数
        if (after_decimal_point < getrequired) {
            cent_length = getrequired;
            //如果小数点后的位数大于获取格式化后小数点后0的位数，且小于格式化后小数点的位数   0.0##>23.33>0.0
        } else if (after_decimal_point > getrequired && after_decimal_point < after_format_length) {
            cent_length = getrequired;
            //小数点后的位数和比填数相等
        } else if (after_decimal_point == getrequired) {
            cent_length = getrequired;
            //如果如果小数点后的位数大于格式后的位数
        } else {
            cent_length =  after_format_length;
        }
        newNum =newNum.toFixed(cent_length)
    }else{
        newNum = num.toString();
    }
    if (isThousand) {
        // 对整数部分进行千分位格式化.
        var processedNumber=newNum.split('.');
        var integerPart=processedNumber[0]?processedNumber[0]:null;
        var decimalPart=processedNumber[1]?processedNumber[1]:null;
        // const [integerPart, decimalPart] = newNum.split('.');
        // 带小数的数字
        if(decimalPart){
            newNum = integerPart.replace(/\B(?=(\d{3})+(?!\d))/g, ',') + '.' + decimalPart;
        }else{ // 整数
            newNum = integerPart.replace(/\B(?=(\d{3})+(?!\d))/g, ',') ;
        }
    }
    return newNum;
}
